import {BasicColumn, FormSchema} from '/@/components/Table';
import {render} from '/@/utils/common/renderUtils';
import {UploadBizType} from '/@/enums/uploadEnum';

export const columns: BasicColumn[] = [
  {
    title: '图标',
    dataIndex: 'logo',
    align: 'left',
    width: 50,
    customRender: ({ text }) => {
      return render.renderImagePreview({
        imageList: [{src: text, width: 45, preview: false}]
      })
    }
  },
  {
    title: '登录模式',
    width: 150,
    align: 'left',
    dataIndex: 'name',
  },
  {
    title: '场景',
    width: 150,
    dataIndex: 'sceneNames',
    customRender: ({ text }) => {
      return render.renderTag(text, 'green')
    }
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'hasClient',
    label: 'hasClient',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true
  },
  // {
  //   field: 'code',
  //   label: '标识符',
  //   component: 'Input',
  //   required: true
  // },
  {
    field: 'grantType',
    label: '授权方式',
    helpMessage: 'OAuth客户端与该值进行绑定, 便于进行OAuth2等授权',
    component: 'Input',
    required: true
  },
  {
    field: 'configKey',
    label: '配置参数',
    helpMessage: '所有第三方配置参数都去配置中心进行配置, 未配置时, 身份源不会生效',
    component: 'Input',
    required: true,
    slot: 'configKey',
  },
  {
    label: '场景',
    field: 'scenes',
    required: true,
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'login_scene',
      placeholder:'请选择场景',
      mode: 'multiple',
    }
  },

  {
    field: 'displayName',
    label: '显示名称',
    component: 'Input'
  },
  {
    field: 'isAskBind',
    label: '询问绑定',
    helpMessage: '当没开启询问绑定时, 若没有绑定任何账号, 则自动创建新账号并进行绑定',
    component: 'RadioGroup',
    defaultValue: true,
    componentProps: {
      options: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
    }
  },

  {
    field: 'bindClient',
    label: '关联客户端',
    ifShow: ({ values }) => values.hasClient === '1',
    component: 'Input',
    slot: 'bindClient',
  },

  {
    label: '图标',
    field: 'logo',
    component: 'JImageUpload',
    componentProps: {
      fileMax:1,
      bizType: UploadBizType.GENERAL_IMAGE
    },
  },
];



export const fieldColumns: BasicColumn[] = [
  {
    title: '键值',
    width: 60,
    dataIndex: 'formKey',
  },
  {
    title: '标签',
    width: 60,
    dataIndex: 'formLabel',
  },
  {
    title: '占位符',
    width: 120,
    dataIndex: 'placeholder',
  },
  {
    title: '组件',
    width: 60,
    dataIndex: 'component',
    customRender: ({ text }) => {
      return render.renderTag(render.renderDict(text, 'ui_component'), 'green')
    }
  }
];

export const fieldFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show: false
  },
  {
    field: 'formKey',
    label: '键值',
    component: 'Input',
    required: true
  },
  {
    field: 'formLabel',
    label: '名称',
    component: 'Input',
    required: true
  },
  {
    field: 'placeholder',
    label: '占位符',
    component: 'Input',
    required: false
  },
  {
    field: 'required',
    component: 'RadioGroup',
    label: '必填',
    defaultValue: false,
    required: true,
    componentProps: {
      options: [
        {
          label: '是',
          value: true,
        },
        {
          label: '否',
          value: false,
        },
      ],
    },
  },
  {
    field: 'component',
    label: '组件',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'ui_component',
    }
  },
];
